home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / UIFlow 1.0.1 / UIFlow Source / CFDFront / TDataView.cp < prev    next >
Encoding:
Text File  |  1992-02-21  |  14.5 KB  |  422 lines  |  [TEXT/MPS ]

  1. #pragma segment MenuOption
  2. //*********************************************************************************
  3. //    TMyDialogTEView - Methods
  4. //*********************************************************************************
  5. // ------------------------------------------------------------------------------------------
  6. //    DialogTEView initializer
  7. // ------------------------------------------------------------------------------------------
  8. pascal void TMyDialogTEView::IDialogTEView(TDocument *itsDocument, TView *itsSuperView, VPoint *
  9.         itsLocation, VPoint *itsSize, SizeDeterminer itsHDeterminer, SizeDeterminer itsVDeterminer, 
  10.         Rect *itsInset, TextStyle *itsTextStyle, short itsJustification, Boolean itsStyleType, Boolean
  11.         itsAutoWrap)
  12.         {
  13.         inherited::IDialogTEView(itsDocument, itsSuperView,itsLocation, itsSize, itsHDeterminer,itsVDeterminer, 
  14.               itsInset,itsTextStyle,itsJustification,itsStyleType, itsAutoWrap);
  15.        }
  16.  
  17. // ------------------------------------------------------------------------------------------
  18. //    select the edit text box for cursor insertion
  19. // ------------------------------------------------------------------------------------------
  20. pascal void TMyDialogTEView::InstallSelection(Boolean wasActive, Boolean beActive)
  21.     {
  22. //    if (((TDataView *) fEditText->fSuperView)->fPoint == NULL && beActive)
  23. //        {
  24. //        TWarning * tWarning;
  25. //        TWindow    * aWindow;
  26.         
  27. //        aWindow = NewTemplateWindow(kWarnMe,(TDocument*) fDocument);
  28. //        tWarning = (TWarning *) aWindow->FindSubView('WARN');
  29. //        tWarning->IWarning(3,NULL);
  30. //        tWarning->ShowWarning();
  31. //        ((TDataView *)fEditText->fSuperView)->ForceRedraw();
  32. //        return;
  33. //        }
  34.     inherited::InstallSelection(wasActive,beActive);
  35.     }
  36.     
  37. // ------------------------------------------------------------------------------------------
  38. //    Make the typing command
  39. // ------------------------------------------------------------------------------------------
  40. pascal struct TTETypingCommand * TMyDialogTEView::DoMakeTypingCommand(short ch)
  41.     {
  42.     TMyTypingCommand * aTypingCommand;
  43.  
  44.     aTypingCommand = new TMyTypingCommand;
  45.     if (aTypingCommand == NULL)
  46.         return (TTETypingCommand *) gNoChanges;
  47.     aTypingCommand->ITETypingCommand(this, ch);
  48.     return (TTETypingCommand *) aTypingCommand;
  49.     }
  50.  
  51. // ------------------------------------------------------------------------------------------
  52. //    Store the Data
  53. // ------------------------------------------------------------------------------------------
  54. void TMyDialogTEView::StoreData(void)
  55.     {
  56.     ((TDataView *) fEditText->fSuperView)->StoreData();
  57.     return;
  58.     }
  59.  
  60. //*********************************************************************************
  61. //    TMyTypingCommand - Methods
  62. //*********************************************************************************
  63. // ------------------------------------------------------------------------------------------
  64. //    Add the character into the field
  65. // ------------------------------------------------------------------------------------------
  66. pascal void TMyTypingCommand::AddCharacter(short aChar)
  67.     {
  68.     char test;
  69.     
  70.     test = aChar;
  71.     if ((aChar >= '0' && aChar <= '9') || aChar == '.' || aChar == '-')
  72.         test = chReturn;
  73.         
  74.     switch (test)
  75.         {
  76.         case chFwdDelete:
  77.         case chBackspace:
  78.         case chTab:
  79.         case chReturn:
  80.         case chEnd:
  81.         case chDown:
  82.         case chEscape:
  83.         case chHome:
  84.         case chLeft:
  85.         case chRight:
  86.         case chUp:
  87.             inherited::AddCharacter(aChar);
  88.             ((TMyDialogTEView *) fTEView)->StoreData();
  89.             break;
  90.         default:
  91.             SysBeep (3);
  92.             return;
  93.         }
  94.     }
  95.  
  96. //*********************************************************************************
  97. //    TDataView - Methods
  98. //        inherits all methods and vars from TDialogView
  99. //        overrides method : DoChoice
  100. //*********************************************************************************
  101. //    init this from our own resource.
  102. // --------------------------------------------------------------------------------------------------
  103. pascal void TDataView::IDataView (void)
  104.     {
  105.     TWindow         * aWindow;
  106.  
  107.     aWindow = this->GetWindow();                                                                    // get the window reference
  108.     fGeom = (TGeomView *) aWindow->FindSubView('geom');                            // get GeomView reference
  109.     fScroll = (TScroller *) aWindow->FindSubView('VW02');                            // get scroll bar reference
  110.     tWall    = (TRadio *) aWindow->FindSubView('WALL');
  111.     tIflw        = (TRadio *) aWindow->FindSubView('IFLW');
  112.     tSymm    = (TRadio *) aWindow->FindSubView('SYMM');
  113.     tOflw    = (TRadio *) aWindow->FindSubView('OFLW');
  114.     tIntr        = (TRadio *) aWindow->FindSubView('INTR');
  115.     return;
  116.     }
  117. // --------------------------------------------------------------------------------------------------
  118. //    Draw the View 
  119. // --------------------------------------------------------------------------------------------------
  120. pascal void TDataView::Draw(Rect * /*thisRect*/)                                            // Draws the view seen in the window. 
  121.     {    
  122.     Point pen;
  123.     Rect  tRect;
  124.     pen.v = 1;     pen.h = 1;
  125.     tRect.top = 0;
  126.     tRect.left = 0;
  127.     tRect.right = (short) fSize.h;
  128.     tRect.bottom = (short) fSize.v;
  129.  
  130.     HLock((Handle) this);
  131.     RGBForeColor(&GridLineColor);                                                                    // set color
  132.     PenPixPat(GridLinePat);
  133.     
  134.     this->Adorn(&tRect,pen,adnLineBottom);
  135.     this->Adorn(&tRect,pen,adnLineLeft);
  136.     HUnlock((Handle) this);
  137.     return;
  138.     } 
  139.  
  140. // --------------------------------------------------------------------------------------------------
  141. //    If the SuperView is changed want to move TinformationView
  142. // --------------------------------------------------------------------------------------------------
  143. pascal void TDataView::SuperViewChangedSize(VPoint *delta, Boolean /*invalidate*/)
  144.     {
  145.     VPoint newLoc, newLoc1;
  146.     
  147.     newLoc.h = fLocation.h  + delta->h;
  148.     newLoc.v = fLocation.v;
  149.     newLoc1.h = fSize.h;
  150.     newLoc1.v = fSize.v + delta->v;
  151.     if (fShown)
  152.         {
  153.         this->Locate(newLoc.h,newLoc.v,true);
  154.         this->Resize(newLoc1.h,newLoc1.v,true);
  155.         }
  156.     else
  157.         {
  158.         this->Locate(newLoc.h,newLoc.v,false);
  159.         this->Resize(newLoc1.h,newLoc1.v,false);
  160.         }
  161.     return;    
  162.     }
  163.  
  164. // --------------------------------------------------------------------------------------------------
  165. //    Display the data view
  166. // --------------------------------------------------------------------------------------------------
  167. void TDataView::ShowIt(void)
  168.     {
  169.     VCoordinate     width, height;
  170.     TPoint            * tPt;
  171.     TWindow         * aWindow;
  172.  
  173.     aWindow = this->GetWindow();                                                                    // get the window reference    
  174.     matrix = ((TGeomView *) fGeom)->fCDocument->fPointMatrix;                // get matrix reference
  175.     
  176.     height    = fScroll->fSize.v;                                                                        // calculate new size
  177.     width    = fScroll->fSize.h - 116;
  178.     fScroll->Resize(width,height,true);                                                            // change & redraw
  179.     fGeom->Focus();                                                                                        // focus on geometry
  180.     this->Show(true,true);                                                                                // bring view to front
  181.     fGeom->Update();
  182.  
  183.     if (((TGeomView *) fGeom)->fSegment)                                                    // segment is already selected
  184.         {
  185.         this->ShowData((TSegPoint *)((TGeomView *) fGeom)->fSPoint);            // just show the data
  186.         return;
  187.         }
  188.     else if (((TGeomView *) fGeom)->fSPoint != NULL)                                    // have a point no segment
  189.         {
  190.         TSegPoint * sPt;
  191.         TRow        *    side;
  192.         
  193. //        if (((TGeomView *) fGeom)->fSPoint->IsInterior())
  194. //            this->ShowData((TSegPoint *) ((TGeomView *) fGeom)->fSPoint);    // is interior point
  195. //        else
  196.         if (!((TGeomView *) fGeom)->fSPoint->IsInterior())
  197.             {
  198.             tPt = ((TGeomView *) fGeom)->fSPoint;                                            // save the old selected point
  199.             side = ((TGeomView *) fGeom)->fSSide;
  200.             matrix->DoHighlight();                                                                         // unhighlight old point
  201.             ((TGeomView *) fGeom)->UnSelect();                                                // unselect everything
  202.         
  203.             sPt = matrix->FindSegment(tPt,side);                                                // get the segment
  204.             ((TGeomView *) fGeom)->Select(sPt,true,side);                                // select new segment
  205.             matrix->DoHighlight();                                                                         // highlight new segment
  206.     
  207.             this->Focus();
  208.             this->ShowData(sPt);                                                                        // display the data
  209.             return;
  210.             }
  211.         else
  212.             {
  213.             matrix->DoHighlight();
  214.             ((TGeomView *) fGeom)->UnSelect();
  215.             }
  216.         }
  217.  
  218.  
  219.     tPt = ((TGeomView *) fGeom)->fCDocument->fInterior;
  220.     ((TGeomView *) fGeom)->Select(tPt,false,NULL);
  221.     this->ShowData((TSegPoint *) tPt);
  222.     return;
  223.     }
  224.  
  225. // --------------------------------------------------------------------------------------------------
  226. //    Hide the data view
  227. // --------------------------------------------------------------------------------------------------
  228. void TDataView::HideIt(void)
  229.     {
  230.     VCoordinate     width, height;
  231.     
  232.     this->DeselectCurrentEditText();                                                                    // dispose current TEView
  233.  
  234.     height    = fScroll->fSize.v;                                                                            // calculate new size
  235.     width    = fScroll->fSize.h + 116;
  236.     fScroll->Resize(width,height,true);                                                                // resize & redraw
  237.     this->Show(false,true);                                                                                // hide it
  238.     fGeom->Focus();                                                                                            // focus on geometry
  239.     
  240.     if (fPoint->IsInterior())                                                                                    // interior point?
  241.         ((TGeomView *) fGeom)->UnSelect();                                                        // unselect it
  242.         
  243.     else if (((TGeomView *) fGeom)->fSSide != NULL)                                            // have a side?
  244.         {
  245.         TPoint    *    tPt;
  246.         TRow    *    side;
  247.         
  248.         tPt = ((TGeomView *) fGeom)->fSPoint;                                                    // save the point
  249.         side = ((TGeomView *) fGeom)->fSSide;
  250.         matrix->DoHighlight();                                                                                 // highlight new segment
  251.         ((TGeomView *) fGeom)->UnSelect();                                                        // unselect the segment
  252.         ((TGeomView *) fGeom)->Select(tPt,false,side);                                        // reselect the point
  253.         matrix->DoHighlight();                                                                                 // highlight new segment
  254.         }
  255.     }
  256.         
  257. // --------------------------------------------------------------------------------------------------
  258. //    Show the point data
  259. // --------------------------------------------------------------------------------------------------
  260. void TDataView::ShowData(TSegPoint * tPt)
  261.     {
  262.     TWindow    *     aWindow;
  263.     TEditText    *    iText;
  264.     TCluster    * tCluster;
  265.     TRadio        * tRadio;
  266.     IDType        rCurrent;
  267.     short index;
  268.     char  string[20];
  269.     StringPtr pString;
  270.     
  271.     fPoint = tPt;
  272.     wRec.theData = tPt->GetData();                                                    // the data
  273.  
  274.     aWindow = this->GetWindow();                                                        // get the window pointer
  275.     for (index=1; index< 12; index++)                                                // display each piece of data
  276.         {
  277.         this->GetControlName(index,"CK");                                            // get scroller name
  278.         iText = (TEditText *) aWindow->FindSubView(tbox.boxID);        // find the data box
  279.         
  280.         sprintf(string,"%e",wRec.iData[index-1]);                                // convert the data to string
  281.         pString = c2pstr(string);                                                            // convert to pascal type
  282.         iText->SetText(pString,true);
  283.         }
  284.                 
  285.     tCluster     = (TCluster *) aWindow->FindSubView('WTYP');            // get the cluster view
  286.     rCurrent    = tCluster->ReportCurrent();                                        // get current selected button
  287.  
  288.     switch (fPoint->GetSectionType())
  289.         {
  290.         case Wall:
  291.             tWall->Toggle(true);
  292.             break;
  293.         case InFlow:
  294.             tIflw->Toggle(true);
  295.             break;
  296.         case Symm:
  297.             tSymm->Toggle(true);
  298.             break;
  299.         case OutFlow:
  300.             tOflw->Toggle(true);
  301.             break;
  302.         case Grid:
  303.             tIntr->Toggle(true);            
  304.             tWall->DimState(true,true);                                                    // dim other controls
  305.             tIflw->DimState(true,true);
  306.             tSymm->DimState(true,true);
  307.             tOflw->DimState(true,true);
  308.             break;
  309.         }
  310.  
  311.     tRadio = (TRadio *) aWindow->FindSubView(rCurrent);                    // turn off old value
  312.     tRadio->Toggle(true);
  313.  
  314.     if (tWall->IsDimmed() && !fPoint->IsInterior())                            // controls dimmed & boundry point
  315.         {
  316.         tWall->DimState(false,true);
  317.         tIflw->DimState(false,true);
  318.         tSymm->DimState(false,true);
  319.         tOflw->DimState(false,true);
  320.         }        
  321.     return;
  322.     }
  323.     
  324. // ------------------------------------------------------------------------------------------
  325. //    DoChoice Method - get the user response in this window
  326. // ------------------------------------------------------------------------------------------
  327. pascal void TDataView::DoChoice(TView *origView, short itsChoice)
  328.     {
  329.     TRow            * side;
  330.     
  331.     if (itsChoice == mRadioHit)
  332.         {
  333.         if (origView == tIntr)                                                                // interior point?
  334.             {
  335.             TSegPoint * t;                                                                        // get interior point
  336.             t = (TSegPoint *) ((TCFDFrontDocument *) (((TGeomView *) fGeom)->fCDocument))->fInterior;
  337.             this->ShowData(t);                                                                // display the data
  338.             ((TGeomView *) fGeom)->Focus();                                        // focus on geometry
  339.             matrix->DoHighlight();                                                            // unhighlight old
  340.             ((TGeomView *) fGeom)->UnSelect();                                    // unselect old
  341.             ((TGeomView *) fGeom)->Select(t,false,NULL);                    // select interior point
  342.             }
  343.         else
  344.             {
  345.             if (fPoint->IsInterior())                                                            // point is interior
  346.                 SysBeep (3);
  347.             else
  348.                 {            
  349.                 side = ((TGeomView *) fGeom)->fSSide;
  350.                 ((TGeomView *) fGeom)->Focus();
  351.                 PenMode(srcXor);
  352.                 matrix->DoDrawSegment();                                                // erase endpoints
  353.  
  354.                 if (origView == tWall)
  355.                     matrix->SetSegment(fPoint, side, Wall);
  356.                 else if (origView == tIflw)
  357.                     matrix->SetSegment(fPoint, side, InFlow);
  358.                 else if (origView == tOflw)
  359.                     matrix->SetSegment(fPoint, side, OutFlow);
  360.                 else if (origView == tSymm)
  361.                     matrix->SetSegment(fPoint, side, Symm);
  362.                 matrix->DoDrawSegment();                                                    // erase endpoints
  363.                 }
  364.             }
  365.         }
  366.     this->Focus();
  367.     inherited::DoChoice(origView,itsChoice);
  368.     }
  369.  
  370. // ------------------------------------------------------------------------------------------
  371. //    Make a dialog view used for textedit fields
  372. // ------------------------------------------------------------------------------------------
  373. pascal struct TDialogTEView * TDataView::MakeTEView(void)
  374.     {
  375.     TMyDialogTEView * aDialogTEView;
  376.     
  377.     aDialogTEView = new TMyDialogTEView;
  378.     if (aDialogTEView == NULL)
  379.         return (TDialogTEView *) gNoChanges;
  380.     HLock((Handle) this);
  381.     aDialogTEView->IDialogTEView(NULL, NULL, &gZeroVPt, &gZeroVPt, sizeRelSuperView, sizeVariable,
  382.                                 &gZeroRect, &gSystemStyle, teJustSystem, kWithoutStyle, false);
  383.     HUnlock((Handle) this);
  384.  
  385.     aDialogTEView->fMinAhead = 1;                                                            // Don't _jump_ the view ahead 
  386.                                                                                                                 // when autoscrolling for
  387.                                                                                                                 // scrollselectionintoview
  388.     return (TDialogTEView *) aDialogTEView;
  389.     }
  390.     
  391. // ------------------------------------------------------------------------------------------
  392. //    Set the text for this point
  393. // ------------------------------------------------------------------------------------------
  394. void TDataView::StoreData(void)
  395.     {
  396.     short            index;
  397.     Str255            pString;
  398.     char             * string;
  399.     TWindow        *    aWindow;
  400.     TEditText        *    iText;
  401.     
  402.     if (fPoint == NULL)                                                                                // no point to store data for    
  403.         return;
  404.  
  405.     aWindow = this->GetWindow();                                                                // get the window pointer
  406.     for (index=1;index<12;index++)                                                            // display each piece of data
  407.         {
  408.         this->GetControlName(index,"CK");                                                    // get scroller name
  409.         iText = (TEditText *) aWindow->FindSubView(tbox.boxID);                // find the data box
  410.         if (iText == fCurrentEditText)                                                            // same box?
  411.             {
  412.             float num;
  413.             
  414.             iText->GetText(pString);
  415.             string = p2cstr((StringPtr) pString);
  416.             num = atof(string);
  417.             wRec.iData[index-1] = num;
  418.             break;
  419.             }
  420.         }
  421.     ((TSegPoint *) fPoint)->SetData(wRec.theData);
  422.     }